//
//  ICMAppointmentPreviewView.m
//  ICrEAM
//
//  Created by Cty on 2016/11/09.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMAppointmentPreviewView.h"
#import "PreviewItemAndComponentView.h"
#import "PreviewBaseItemView.h"
#import "PreviewItemsModel.h"
#import "PreviewCompsModel.h"
#import "PreviewActivityView.h"
#define DisplayWidth      ActualWidth(984)
#define StartLeftDistance      ActualWidth(80)
#define ItemWidth      ActualWidth(260)
#define ItemHeight      ActualHeight(50)
#define titleDistance     ActualHeight(10)

@interface ICMAppointmentPreviewView()

//零件维修类型
@property (nonatomic,strong) NSString *repairTypeNamePart;

//项目维修类型
@property (nonatomic,strong) NSString *repairTypeNameLabour;

@property (nonatomic,strong) NSMutableArray *labourArray;

@property (nonatomic,strong) NSMutableArray *partArray;

@end

@implementation ICMAppointmentPreviewView

-(NSMutableArray *)labourArray{
    if (!_labourArray) {
        _labourArray = [NSMutableArray array];
    }
    return _labourArray;
}

-(NSMutableArray *)partArray{
    if (!_partArray) {
        _partArray = [NSMutableArray array];
    }
    return _partArray;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        
    }
    return self;
}

- (void)setUpChildView{
    
    
    UILabel *label  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20),ActualHeight(20), DisplayWidth, ActualHeight(20))];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = TitleColor_Dark;
    label.font = NaviFont;
    label.text = @"预约单基本信息";
    //1.车辆信息块
    //第一行分割线
    UIView *firstLine = [[UIView alloc] initWithFrame:CGRectMake(label.x, label.bottomEdge+ActualHeight(20), DisplayWidth+ActualWidth(20), 1)];
    
    firstLine.backgroundColor = BackgroundColor_Gray;
    
    
    //车牌信息
    UIImage *image = [UIImage imageNamed:Appointment_Car];
    // 当没有设置imageView的frame时
    // 图片控件所占的区域与加载的图片大小保持一致
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    
    imageView.frame =CGRectMake(ActualHeight(20), firstLine.bottomEdge+ActualHeight(48), ActualWidth(30), ActualHeight(30));
    
    //设置图片的显示模式
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    //车牌号
    PreviewBaseItemView *carNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, firstLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                   @"车牌号" andSubTitle:self.basicInfoModel.LICENSE];
    //VIN
    PreviewBaseItemView *vinNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(carNum.rightEdge, firstLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                   @"VIN" andSubTitle:self.basicInfoModel.VIN];
    
    //购车发票日期
    PreviewBaseItemView *invoicesDate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(vinNum.rightEdge, firstLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                         @"购车发票日期" andSubTitle:StrIsZero_gdm(self.basicInfoModel.SALES_DATE)?@"":[ICrEAMTool getDateWithTimeInterval:self.basicInfoModel.SALES_DATE]];
    
    //行驶里程
    PreviewBaseItemView *mileage = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(invoicesDate.rightEdge, firstLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                    @"行驶里程" andSubTitle:self.basicInfoModel.IN_MILEAGE];
    //车型
    PreviewBaseItemView *carType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, carNum.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                    @"车型" andSubTitle:self.basicInfoModel.MODEL_NAME];
    
    
    
    [self addSubview:firstLine];
    [self addSubview:imageView];
    [self addSubview:label];
    [self addSubview:carNum];
    [self addSubview:vinNum];
    [self addSubview:invoicesDate];
    [self addSubview:mileage];
    [self addSubview:carType];

    
    //2.车主信息块
    //第二行分割线
    UIView *secondLine = [[UIView alloc] initWithFrame:CGRectMake(carType.x, carType.bottomEdge+ActualHeight(20), ActualWidth(1024)-carType.x, 1)];
    
    secondLine.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:secondLine];
    
    //车主图片
    //车牌信息
    UIImage *imageOwner = [UIImage imageNamed:Appointment_CarOwner];
    // 当没有设置imageView的frame时
    // 图片控件所占的区域与加载的图片大小保持一致
    UIImageView *imageViewOwner = [[UIImageView alloc]initWithImage:imageOwner];
    
    imageViewOwner.frame =CGRectMake(ActualHeight(20), secondLine.bottomEdge+ActualHeight(48), ActualWidth(30), ActualHeight(30));
    
    //设置图片的显示模式
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    [self addSubview:imageViewOwner];
    
    //车主姓名
    PreviewBaseItemView *ownerName = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, secondLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                      @"车主姓名" andSubTitle:self.basicInfoModel.OWNER_NAME];
    
    [self addSubview:ownerName];
    //车主手机
    PreviewBaseItemView *ownerPhone = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(ownerName.rightEdge, secondLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                       @"车主手机" andSubTitle:self.basicInfoModel.OWNER_MOBILE];
    
    [self addSubview:ownerPhone];
    
    //预约人姓名
    PreviewBaseItemView *appointedName = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(ownerPhone.rightEdge, secondLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                          @"预约人姓名" andSubTitle:self.basicOtherModel.CONTACTOR_NAME];
    [self addSubview:appointedName];
    //预约人手机
    PreviewBaseItemView *appointedPhone = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(appointedName.rightEdge, secondLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                           @"预约人手机" andSubTitle:self.basicOtherModel.CONTACTOR_MOBILE];
    [self addSubview:appointedPhone];
    //车主性质
    PreviewBaseItemView *ownerType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, appointedPhone.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                      @"车主性质" andSubTitle:[ICrEAMTool getCodeModelForCode:self.basicInfoModel.OWNER_PROPERTY].desc];
    
    [self addSubview:ownerType];
    
    //3.详细信息
    //第三行分割线
    UIView *thirdLine = [[UIView alloc] initWithFrame:CGRectMake(ownerType.x, ownerType.bottomEdge+ActualHeight(20), ActualWidth(1024)-carType.x, 1)];
    
    thirdLine.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:thirdLine];
    
    
    //图片
    UIImage *detail = [UIImage imageNamed:Appointment_AppointSelected];
    // 当没有设置imageView的frame时
    // 图片控件所占的区域与加载的图片大小保持一致
    UIImageView *imageViewdetail = [[UIImageView alloc]initWithImage:detail];
    
    imageViewdetail.frame =CGRectMake(ActualHeight(20), thirdLine.bottomEdge+ActualHeight(105), ActualWidth(30), ActualHeight(30));
    
    //设置图片的显示模式
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    [self addSubview:imageViewdetail];
    
    //预约进厂日期
    PreviewBaseItemView *receiveDate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                        @"预约进厂日期" andSubTitle:StrIsZero_gdm(self.basicOtherModel.BOOKING_COME_TIME)?@"":[ICrEAMTool getDateHourAndMinWithTimeInterval:self.basicOtherModel.BOOKING_COME_TIME]];
    
    [self addSubview:receiveDate];
    
    //接待服务顾问
    PreviewBaseItemView *reception = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(receiveDate.rightEdge, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                      @"接待服务顾问" andSubTitle:self.basicOtherModel.EMPLOYEE_NAME];
    
    [self addSubview:reception];
    
    //预约工位
    PreviewBaseItemView *appointmentStation = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(reception.rightEdge, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                       @"预约工位" andSubTitle:self.basicOtherModel.LABOUR_POSITION_NAME];
    [self addSubview:appointmentStation];
    
    //预计施工时间
    float workTime = [self.basicOtherModel.EST_REPAIR_TIME floatValue];
    NSString *workTimeText;
    NSInteger workTimeHour = workTime;
    float workTimeMin = workTime - workTimeHour;
    workTimeText = workTimeHour>0?[NSString stringWithFormat:@"%ld小时",workTimeHour]:@"";
    NSString *stationTime = workTimeMin>0?[NSString stringWithFormat:@"%@%ld分钟",workTimeText,((NSInteger)(workTimeMin*60))]:workTimeText;
    
    PreviewBaseItemView *exceptTime = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(appointmentStation.rightEdge, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                      @"预计施工时间" andSubTitle:StrIsZero_gdm(self.basicOtherModel.EST_REPAIR_TIME)?@"":stationTime];
    
    [self addSubview:exceptTime];
    
    //预约服务类型
    PreviewBaseItemView *serviceType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, exceptTime.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                     @"预约服务类型" andSubTitle:@"维修"];
    [self addSubview:serviceType];
    
    
    //预约服务子类型
    PreviewBaseItemView *subServiceType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(serviceType.rightEdge, exceptTime.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                        @"预约服务子类型" andSubTitle:self.basicOtherModel.BOOKING_REPAIR_TYPE_NAME];
    [self addSubview:subServiceType];

    //预约单号
    PreviewBaseItemView *appointmentNo = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(subServiceType.rightEdge, exceptTime.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                            @"预约单号" andSubTitle:self.basicInfoModel.BOOKING_ORDER_NO];
    [self addSubview:appointmentNo];
    
    
    //开单时间
    PreviewBaseItemView *appointmentCreatTime = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(appointmentNo.rightEdge, exceptTime.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                           @"开单时间" andSubTitle:StrIsZero_gdm(self.basicOtherModel.SHEET_CREATE_DATE)?@"":[ICrEAMTool getDateHourAndMinWithTimeInterval:self.basicOtherModel.SHEET_CREATE_DATE]];
    [self addSubview:appointmentCreatTime];
    
    //接车地址
    PreviewBaseItemView *getcarLocation = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, appointmentCreatTime.bottomEdge+titleDistance, ItemWidth*2, ItemHeight) andTitle:
                                               @"接车地址" andSubTitle:self.basicOtherModel.DRIVE_ADD];
    [self addSubview:getcarLocation];
    
    //送车地址
    PreviewBaseItemView *sendCarAddress = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(getcarLocation.rightEdge, appointmentCreatTime.bottomEdge+titleDistance, ItemWidth*2, ItemHeight) andTitle:
                                           @"送车地址" andSubTitle:self.basicInfoModel.DELIVER_ADD];
    [self addSubview:sendCarAddress];
    
    
    //备注
    PreviewBaseItemView *comment = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, getcarLocation.bottomEdge+titleDistance, ItemWidth*2, ItemHeight) andTitle:
                                          @"备注" andSubTitle:self.basicOtherModel.REMARK];
    
    [self addSubview:comment];
    
    
    //分割块
    UIView *sperator1 = [[UIView alloc] initWithFrame:CGRectMake(0, comment.bottomEdge+ActualHeight(20), ScreenWidth, 1)];
    
    sperator1.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator1];
    
    
    UIView *block1 = [[UIView alloc] initWithFrame:CGRectMake(0, sperator1.bottomEdge, ScreenWidth, ActualHeight(13))];
    
    block1.backgroundColor = Color(0xf1f3f3);
    
    [self addSubview:block1];
    
    UIView *sperator2 = [[UIView alloc] initWithFrame:CGRectMake(0, block1.bottomEdge, ScreenWidth, 1)];
    
    sperator2.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator2];
    


    
    
    //6.所选活动
    //所选活动title
    UILabel *selectedActivity  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20), sperator2.bottomEdge+ActualHeight(20), DisplayWidth, ActualHeight(20))];
    selectedActivity.textAlignment = NSTextAlignmentLeft;
    selectedActivity.textColor = [UIColor colorWithHex:0x000000];
    
    selectedActivity.textColor = TitleColor_Dark;
    selectedActivity.font = NaviFont;
    selectedActivity.text = @"所选活动";
    [self addSubview:selectedActivity];
    
    //第6行分割线
    UIView *sixthLine = [[UIView alloc] initWithFrame:CGRectMake(label.x, selectedActivity.bottomEdge+ActualHeight(20), ActualWidth(1024)-carType.x, 1)];
    
    sixthLine.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sixthLine];
    
    PreviewActivityView *activity = [PreviewActivityView creatWithFrame:CGRectMake(ActualWidth(60), sixthLine.bottomEdge+ActualWidth(40), ScreenWidth-ActualWidth(60), ActualHeight(120)) dataSource:self.activityModel.TT_ACTIVITY];
    [self addSubview:activity];

    //分割块
    UIView *sperator7 = [[UIView alloc] initWithFrame:CGRectMake(0, activity.bottomEdge+ActualHeight(35), ScreenWidth, 1)];
    
    sperator7.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator7];
    
    
    UIView *block4 = [[UIView alloc] initWithFrame:CGRectMake(0, sperator7.bottomEdge, ScreenWidth, ActualHeight(13))];
    
    block4.backgroundColor = Color(0xf1f3f3);
    
    [self addSubview:block4];
    
    UIView *sperator8 = [[UIView alloc] initWithFrame:CGRectMake(0, block4.bottomEdge, ScreenWidth, 1)];
    
    sperator8.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator8];
    
    //7.项目和零件
    //项目和零件title
    UILabel *projectTitle  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20), sperator8.bottomEdge+ActualHeight(30), DisplayWidth, ActualHeight(20))];
    projectTitle.textAlignment = NSTextAlignmentLeft;
    projectTitle.text = @"项目和零件";
    projectTitle.textColor = TitleColor_Dark;
    projectTitle.font = NaviFont;
    [self addSubview:projectTitle];
    
    
    //合计
    UILabel *total  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(35), projectTitle.bottomEdge+ActualHeight(30), DisplayWidth, ActualHeight(35))];
    total.textAlignment = NSTextAlignmentLeft;
    total.textColor = TitleColor_Dark;
    total.text = @"    合计";
    total.backgroundColor = Color(0xf0f0f0);
    [self addSubview:total];
    
    //    //第8行分割线
    //    UIView *eighthLine = [[UIView alloc] initWithFrame:CGRectMake(ActualWidth(30), total.bottomEdge+ActualHeight(20), ActualWidth(1024)-ActualWidth(30), 1)];
    //
    //    eighthLine.backgroundColor = BackgroundColor_Gray;
    //
    //    [self addSubview:eighthLine];
    
    //工时单价
    PreviewBaseItemView *prasePerH = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                      @"工时单价" andSubTitle:self.partsTopModel.LABOUR_PRICE];
    prasePerH.hidden = YES;
    [self addSubview:prasePerH];
    
    //工时单价
//    PreviewBaseItemView *pricePerH = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
//                                      @"工时单价" andSubTitle:self.partsTopModel.LABOUR_AMOUNT];
//    //计算后台精度原因所造成的小数点后几位
//    NSString *LABOUR_AMOUNT = [self notRounding:[self.partsTopModel.LABOUR_AMOUNT floatValue] afterPoint:2];
//    NSString *TOTAL_AMOUNT = [self notRounding:[self.partsTopModel.TOTAL_AMOUNT floatValue] afterPoint:2];
//    NSString *RECEIVE_AMOUNT = [self notRounding:[self.partsTopModel.RECEIVE_AMOUNT floatValue] afterPoint:2];
//    
//    self.partsTopModel.LABOUR_AMOUNT = LABOUR_AMOUNT;
//    self.partsTopModel.TOTAL_AMOUNT = TOTAL_AMOUNT;
//    self.partsTopModel.RECEIVE_AMOUNT = RECEIVE_AMOUNT;

    //工时费
    PreviewBaseItemView *workPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(prasePerH.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                      @"工时费" andSubTitle:self.partsTopModel.LABOUR_AMOUNT];
    
    [self addSubview:workPrice];
    
    //材料费
    PreviewBaseItemView *materialPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(workPrice.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                          @"材料费" andSubTitle:self.partsTopModel.REPAIR_PART_AMOUNT];
    
    [self addSubview:materialPrice];
    
    //总金额
    PreviewBaseItemView *totalPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(materialPrice.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                       @"总金额" andSubTitle:self.partsTopModel.TOTAL_AMOUNT];
    
    [self addSubview:totalPrice];
    
    //工时折旧率
    PreviewBaseItemView *workDesRate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance+ItemWidth, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                        @"工时折扣率" andSubTitle:self.partsTopModel.LABOUR_DISCOUNT_RATE];
    
    [self addSubview:workDesRate];
    
    //材料折旧率
    PreviewBaseItemView *materialDesRate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(workDesRate.rightEdge, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                            @"材料折扣率" andSubTitle:self.partsTopModel.PART_DISCOUNT_RATE];
    
    [self addSubview:materialDesRate];
    //折后总金额
    PreviewBaseItemView *afterPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(materialDesRate.rightEdge, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                       @"折后总金额" andSubTitle:self.partsTopModel.RECEIVE_AMOUNT];
    
    [self addSubview:afterPrice];
    
    self.endFrame = afterPrice.frame;
    
    
    // 排序
    NSMutableArray *labourArrayNew = [NSMutableArray new];
    for (ICMRepairMaintenanceModel *model in self.maintenancesModel.TT_BOOKING_ORDER_LABOUR) {
        if (StrIsZero_gdm(model.REPAIR_TYPE_NAME)) {
            return;
        }
        if (self.repairTypeNameLabour){
            if ([self.repairTypeNameLabour isEqualToString:model.REPAIR_TYPE_NAME]){
                [labourArrayNew PACA_AddObject:model];
                if ([self.maintenancesModel.TT_BOOKING_ORDER_LABOUR indexOfObject:model] == (self.maintenancesModel.TT_BOOKING_ORDER_LABOUR.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                    [self.labourArray PACA_AddObject:newArray];
                }
            }else{
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                [self.labourArray PACA_AddObject:newArray];
                [labourArrayNew removeAllObjects];
                self.repairTypeNameLabour = model.REPAIR_TYPE_NAME;
                [labourArrayNew PACA_AddObject:model];
                if ([self.maintenancesModel.TT_BOOKING_ORDER_LABOUR indexOfObject:model] == (self.maintenancesModel.TT_BOOKING_ORDER_LABOUR.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                    [self.labourArray PACA_AddObject:newArray];
                }
            }
        }else{
            [labourArrayNew PACA_AddObject:model];
            self.repairTypeNameLabour = model.REPAIR_TYPE_NAME;
            if ([self.maintenancesModel.TT_BOOKING_ORDER_LABOUR indexOfObject:model] == (self.maintenancesModel.TT_BOOKING_ORDER_LABOUR.count-1)) {
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                [self.labourArray PACA_AddObject:newArray];
            }
        }
    }
    
    NSMutableArray *partArray = [NSMutableArray array];
    for (ICMRepairPartsModel *model in self.partsArrayModel.TT_BOOKING_ORDER_PART) {
        if (StrIsZero_gdm(model.REPAIR_TYPE_NAME)) {
            return;
        }
        if (self.repairTypeNamePart) {
            if ([self.repairTypeNamePart isEqualToString:model.REPAIR_TYPE_NAME]) {
                [partArray PACA_AddObject:model];
                if ([self.partsArrayModel.TT_BOOKING_ORDER_PART indexOfObject:model] == (self.partsArrayModel.TT_BOOKING_ORDER_PART.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                    [self.partArray PACA_AddObject:newArray];
                }
            }else{
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                [self.partArray PACA_AddObject:newArray];
                [partArray removeAllObjects];
                self.repairTypeNamePart = model.REPAIR_TYPE_NAME;
                [partArray PACA_AddObject:model];
                if ([self.partsArrayModel.TT_BOOKING_ORDER_PART indexOfObject:model] == (self.partsArrayModel.TT_BOOKING_ORDER_PART.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                    [self.partArray PACA_AddObject:newArray];
                }
            }
        }else{
            [partArray PACA_AddObject:model];
            self.repairTypeNamePart = model.REPAIR_TYPE_NAME;
            if ([self.partsArrayModel.TT_BOOKING_ORDER_PART indexOfObject:model] == (self.partsArrayModel.TT_BOOKING_ORDER_PART.count-1)) {
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                [self.partArray PACA_AddObject:newArray];
            }
        }
    }
    
    
    //8.底部 一般维修、常规保养
    
    if(self.labourArray && self.labourArray.count > 0)
    {
        for (int i = 0 ; i < self.labourArray.count; i++) {
            NSMutableArray *arrayItems = self.labourArray[i];
            ICMRepairMaintenanceModel *maintenanceModel = arrayItems[0];
            NSString *typeName = maintenanceModel.REPAIR_TYPE_NAME;
            NSMutableArray *arrayComps = [NSMutableArray array];
            for (NSMutableArray *array in self.partArray) {
                ICMRepairPartsModel *partsModel = array[0];
                if ([partsModel.REPAIR_TYPE_NAME isEqualToString:typeName]) {
                    arrayComps = array;
                }
            }
            //管理工位数据
            NSArray *stationArray = [ICMStationModel mj_objectArrayWithKeyValuesArray:_partsArrayModel];
            
//            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count+stationArray.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andStations:stationArray andType:[NSString stringWithFormat:@"   %@",typeName]];
            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:[NSString stringWithFormat:@"   %@",typeName]];
            [self addSubview:itemAndComponentViewFix];
            self.endFrame = itemAndComponentViewFix.frame;
            
        }
    }
    else
    {
        //管理工位数据
        NSArray *stationArray = [ICMStationModel mj_objectArrayWithKeyValuesArray:_partsArrayModel];

        for (int i = 0 ; i < self.partArray.count; i++) {
            NSMutableArray *arrayComps = self.partArray[i];
            ICMRepairPartsModel *partsModel = arrayComps[0];
            NSString *typeName = partsModel.REPAIR_TYPE_NAME;
            NSMutableArray *arrayItems = [NSMutableArray array];
            for (NSMutableArray *array in self.labourArray) {
                ICMRepairMaintenanceModel *maintenanceModel = array[0];
                if ([maintenanceModel.REPAIR_TYPE_NAME isEqualToString:typeName]) {
                    arrayItems = array;
                }
            }
//            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count+stationArray.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andStations:stationArray andType:[NSString stringWithFormat:@"   %@",typeName]];
        PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:[NSString stringWithFormat:@"   %@",typeName]];
            [self addSubview:itemAndComponentViewFix];
            self.endFrame = itemAndComponentViewFix.frame;
            
        }
        
        
    }

    
    //8.底部 一般维修、常规保养
    //
    //dummy data
//    NSArray *arrayItems = self.maintenancesModel.TT_BOOKING_ORDER_LABOUR;
//    
//    NSArray *arrayComps = self.partsArrayModel.TT_BOOKING_ORDER_PART;
//    
//    PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, afterPrice.bottomEdge+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:@"   一般维修"];
//    [self addSubview:itemAndComponentViewFix];
//    
//    
//    PreviewItemAndComponentView *itemAndComponentViewCare = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, itemAndComponentViewFix.bottomEdge, ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:@"   常规保养"];
//    [self addSubview:itemAndComponentViewCare];
//    
    NSDictionary *dic = @{@"VIN":self.basicInfoModel.VIN,
                          @"OWNER_NO":self.basicInfoModel.OWNER_NO
                          };
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"vinandonw" object:nil userInfo:dic];

    
    
}
-(NSString *)notRounding:(float)price afterPoint:(int)position{
    NSDecimalNumberHandler* roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain scale:position raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
    NSDecimalNumber *ouncesDecimal;
    NSDecimalNumber *roundedOunces;
    
    ouncesDecimal = [[NSDecimalNumber alloc] initWithFloat:price];
    roundedOunces = [ouncesDecimal decimalNumberByRoundingAccordingToBehavior:roundingBehavior];
    
    return [NSString stringWithFormat:@"%@",roundedOunces];
}
@end
